# coding=utf-8
"""
Author: Mr.夏末
@Function: 读取yaml
"""
import os

import yaml

from class11.webkeys import Web

filepath = os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib\cases','login.yaml')

# 打开文件
f = open(filepath,mode='r',encoding='utf8')
# 使用pyyaml读取用例
yamlcases = yaml.safe_load(f)
# print(yamlcases)

# 获取cases用例
# cases = yamlcases.get('loginPage')[0].get('cases')
# print(cases)

#创建关键字对象
web = Web()

for key in yamlcases:
    for cases in yamlcases.get(key):
        # print(cases)
        for case in cases.get('cases'):
            # print(case)
            if case.get('method') == 'openbrowser':
                web.openbrowser(case.get('br'))
                continue

            if case.get('method') == 'get_url':
                web.get_url(case.get('url'))
                continue

            if case.get('method') == 'input':
                web.input(case.get('locator'), case.get('value'))
                continue

            if case.get('method') == 'click':
                web.click(case.get('locator'))
                continue

            if case.get('method') == 'sleep':
                web.sleep(case.get('time'))
                continue